﻿using Entity;
using IDal;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Linq.Expressions;

namespace Dal
{
    /// <summary>
    /// 角色数据访问层
    /// </summary>
    public class RoleInfoDal : BaseDal<RoleInfo>, IRoleInfoDal
    {

        DecorationDbContext _dbContext;

        /// <summary>
        /// base()这里是在调用父类的构造函数
        /// </summary>
        /// <param name="dbContext"></param>
        public RoleInfoDal(DecorationDbContext dbContext) : base(dbContext)
        {
            _dbContext = dbContext;
        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="roleInfo"></param>
        /// <returns></returns>
        public bool CreateRoleInfo(RoleInfo roleInfo)
        {

            _dbContext.RoleInfo.Add(roleInfo);
            int index = _dbContext.SaveChanges();
            if (index > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }


        ///// <summary>
        /// 获取所有角色(没有真正查出来的)
        /// </summary>
        public DbSet<RoleInfo> GetRoleInfosDbSet()
        {
            return _dbContext.RoleInfo;
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateRoleInfo(RoleInfo entity)
        {
            _dbContext.RoleInfo.Update(entity);
            int index = _dbContext.SaveChanges();
            if (index > 0)
            {
                return true;
            }
            return false;
        }
    }
}